package com.younion.action.manage;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.younion.business.IRechargeLogService;
import com.younion.common.base.BaseAction;
import com.younion.common.constants.RechargeType;
import com.younion.common.paginator.Paginator;
import com.younion.vo.CustomerVO;
import com.younion.vo.RechargeLogVO;

import cpcns.jhsks.util.MapCollectionUtils;

/**
 * @author Joe Chen
*/
public class RechargeLogAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	protected static final Log logger = LogFactory.getLog(RechargeLogAction.class);

	private IRechargeLogService rechargeLogService = null;

	private RechargeLogVO rechargeLogVO = new RechargeLogVO();

	private List<RechargeLogVO> rechargeLogList;// 结果集列表
	
	private List<RechargeType> rechargeTypes = Arrays.asList(RechargeType.values());
	/**
	 * 列表：翻页区；数据区
	 */
	@SuppressWarnings("unchecked")
	public String listRechargeLog() {
		try {
			Map paramMap = null;
			if (rechargeLogVO != null) {
				if(rechargeLogVO.getCustomerId() != null){
					rechargeLogVO.setCustomer(new CustomerVO(rechargeLogVO.getCustomerId()));
				}else if(getSessionUser().getCustomer() != null){
					rechargeLogVO.setCustomer(getSessionUser().getCustomer());
				}
				paramMap = MapCollectionUtils.removeEmptyEntry(PropertyUtils.describe(rechargeLogVO));
			}
			// 获取总记录数
			int total = rechargeLogService.getCountByMap(paramMap);
			// 根据总记录数获取分页对象
			Paginator paginator = this.getPaginator(total);
			rechargeLogList = rechargeLogService.get(paramMap, paginator);
			// 保存分页对象
			this.savaPaginator(paginator);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return SUCCESS;
	}

	/**
	 * 新增
	 */
	public String addRechargeLog() {
		return SUCCESS;
	}

	/**
	 * 修改保存，调度Jsp
	 */
	public String editRechargeLog() {
		try {
			rechargeLogVO = rechargeLogService.getById(rechargeLogVO.getId().toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 保存动作
	 */
	public String saveRechargeLog() {
		try {
			rechargeLogVO = rechargeLogService.save(rechargeLogVO);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		request.setAttribute("refreshNavTabId", "listRechargeLog");
		return SUCCESS;
	}

	/**
	 * 删除
	 */
	public String deleteRechargeLog() {
		try {
			String pkId = request.getParameter("key");
			rechargeLogService.remove(Arrays.asList(pkId.split(",")));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		request.setAttribute("refreshNavTabId", "listRechargeLog");
		return SUCCESS;
	}
	/**
	 * 查看鿴
	 */
	public String viewRechargeLog() {
		try {
			String pkId = request.getParameter("key"); 
			rechargeLogVO = rechargeLogService.getById(pkId);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;

	}

	public RechargeLogVO getRechargeLogVO() {
		return rechargeLogVO;
	}

	public void setRechargeLogVO(RechargeLogVO rechargeLogVO) {
		this.rechargeLogVO = rechargeLogVO;
	}

	public void setRechargeLogService(IRechargeLogService rechargeLogService) {
		this.rechargeLogService = rechargeLogService;
	}

	public List<RechargeLogVO> getRechargeLogList() {
		return rechargeLogList;
	}

	public void setRechargeLogList(List<RechargeLogVO> rechargeLogList) {
		this.rechargeLogList = rechargeLogList;
	}

	public List<RechargeType> getRechargeTypes() {
		return rechargeTypes;
	}

	public void setRechargeTypes(List<RechargeType> rechargeTypes) {
		this.rechargeTypes = rechargeTypes;
	}

	public IRechargeLogService getRechargeLogService() {
		return rechargeLogService;
	}
	
	

}